import { ref, computed } from "vue";
import { defineStore } from "pinia";

export const useCounterStore = defineStore(
  "counter",
  () => {
    let user = ref("");
    const getusre = (item) => {
      user.value = item
    };
    let shoplist = ref([]);
    const shopcar = (item) => {
      let flag = shoplist.value.find((v) => v.goods_id == item.goods_id);
      if (flag) {
        flag.num++;
      } else {
        shoplist.value.push({ ...item, num: 1, checked: false });
      }
    };
    return { user, getusre, shoplist, shopcar };
  },
  {
    persist: true,
  }
);
